package main;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GraphicsEnvironment;
import java.awt.Toolkit;
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import java.awt.Font;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.border.TitledBorder;
import javax.swing.JLabel;



public class CurrentState extends JFrame {
	Timer timer = new Timer(true);
	public JTextArea textArea;
	 JPanel panel;
	public JTextField textField;
	 JPanel panel_1;
	 JButton button;
	 private JPanel panel_2;
	 private JLabel lblNewLabel;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					CurrentState frame = new CurrentState();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public CurrentState() {
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

		int width= (int)screenSize.getWidth();
		int height = (int)screenSize.getHeight();
		int taskbarheight = (int) (Toolkit.getDefaultToolkit().getScreenSize().height 
			    - GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().getHeight());
		
		setUndecorated(true);
		setType(Type.UTILITY);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(width-250, height-70-taskbarheight, 250, 70);
		JPanel contentPane = new JPanel();
		contentPane.setBackground(new Color(255, 255, 255));
		contentPane.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		contentPane.add(getPanel_2(), BorderLayout.CENTER);
		timeAttack();
		setAlwaysOnTop(true);
	}
	
	public void timeAttack(){
		
		class reSetArea extends TimerTask{
			public reSetArea(){
			}
			@Override
			public void run() {
				dispose();
			}
		}
		
		reSetArea resetarea = new reSetArea();
		
		timer.schedule(resetarea, 4000);
	}
	public JTextArea getTextArea() {
		if (textArea == null) {
			textArea = new JTextArea();
			textArea.setText("상태가 뜹니다.");
			textArea.setBorder(new EmptyBorder(0, 5, 5, 5));
			textArea.setFont(new Font("맑은 고딕", Font.PLAIN, 12));
		}
		return textArea;
	}
	 JPanel getPanel() {
		if (panel == null) {
			panel = new JPanel();
			panel.setBackground(Color.WHITE);
			panel.setBorder(null);
			panel.setLayout(new BorderLayout(0, 0));
			panel.add(getPanel_1(), BorderLayout.NORTH);
			panel.add(getTextArea(), BorderLayout.CENTER);
		}
		return panel;
	}
	public JTextField getTextField() {
		if (textField == null) {
			textField = new JTextField();
			textField.setOpaque(false);
			textField.setText("익명 [대리 ]");
			textField.setBorder(new EmptyBorder(0, 5, 0, 0));
			textField.setFont(new Font("맑은 고딕", Font.BOLD, 12));
			textField.setColumns(10);
		}
		return textField;
	}
	JPanel getPanel_1() {
		if (panel_1 == null) {
			panel_1 = new JPanel();
			panel_1.setOpaque(false);
			panel_1.setBorder(null);
			panel_1.setLayout(new BorderLayout(0, 0));
			panel_1.add(getButton(), BorderLayout.EAST);
			panel_1.add(getTextField(), BorderLayout.WEST);
		}
		return panel_1;
	}
	 JButton getButton() {
		if (button == null) {
			button = new JButton("");
			button.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					dispose();
				}
			});
			button.setIcon(new ImageIcon("C:\\Program Files\\Mino Corp\\system\\close.png"));
			button.setBorder(null);
			button.setBackground(new Color(176, 224, 230));
		}
		return button;
	}
	private JPanel getPanel_2() {
		if (panel_2 == null) {
			panel_2 = new JPanel();
			panel_2.setBorder(null);
			panel_2.setOpaque(false);
			panel_2.setLayout(new BorderLayout(0, 0));
			panel_2.add(getPanel(), BorderLayout.CENTER);
			panel_2.add(getLblNewLabel(), BorderLayout.WEST);
		}
		return panel_2;
	}
	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("");
			lblNewLabel.setIcon(new ImageIcon("C:\\Program Files\\Mino Corp\\profile\\another.png"));
		}
		return lblNewLabel;
	}
}
